package doc2db.interfaces.action;

import doc2db.DbManager.DbSelects;
import doc2db.UserProp;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author yuriy
 */
public class ExitAction implements ActionListener {

    JFrame f;

    public ExitAction(JFrame __f) {
        f = __f;
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        Dimension dimension = new Dimension(f.getLocation().x, f.getLocation().y);
        new UserProp().writeData(f.getSize(), dimension);

        Object[] options = {"Да", "Нет"};
        int n = JOptionPane.showOptionDialog(null,
                "Выйти из программы?",
                "doc2db - выход",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null, //do not use a custom Icon
                options, //the titles of buttons
                options[0]); //default button title

        if (n == JOptionPane.YES_OPTION) {
            UserProp up = new UserProp();
            try {
                new DbSelects(up.getURL(), up.getUserProp()).close_connect();
            } catch (Exception ex) {
                System.err.println("Can close database connect: " + ex);
            }
            System.exit(0);
        }
    }
}
